import Home from "@/views/Home";
import Blog from "@/views/Blog";
import About from "@/views/About";
import Message from "@/views/Message";
import Project from "@/views/Project";
import Detail from "@/views/Blog/Detail"
import NotFound from "@/views/NotFound";

import "nprogress/nprogress.css";
import { start, done, configure } from "nprogress";
function delay(duration) {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve();
        }, duration);
    });
}

configure({
    trickleSpeed: 20,
    showSpinner: false,
});

function getPageComponent(pageCompResolver) {
    return async () => {
        start();
        if (process.env.NODE_ENV === "development") {
            await delay(100);
        }
        const comp = await pageCompResolver();
        done();
        return comp;
    };
}

// * 路由配置
const routerConfig = [
    // ! 尽量在 RouterLink组件 中使用name属性
    {
        name: "Home", path: "/",
        component: getPageComponent(() =>
            import("@/views/Home")
        ),
        meta: {
            title: "首页"
        }
    },

    // * blog
    {
        name: "Blog", path: "/blog",
        component: getPageComponent(() =>
            import("@/views/Blog")
        ),
        meta: {
            title: "文章"
        }
    },
    {
        name: "CategoryBlog", path: "/blog/cate/:categoryId",
        component: getPageComponent(() =>
            import( "@/views/Blog")
        ),
        meta: {
            title: "文章"
        }
    },
    {
        name: "BlogDetail", path: "/blog/:id",
        component: getPageComponent(() =>
            import( "@/views/Blog/Detail")
        ),
        meta: {
            title: "文章详情"
        }
    },
    // * blog end
    {
        name: "About", path: "/about",
        component: getPageComponent(() =>
            import( "@/views/About")
        ),
        meta: {
            title: "关于我"
        }
    },
    {
        name: "Message", path: "/message",
        component: getPageComponent(() =>
            import("@/views/Message")
        ),
        meta: {
            title: "留言板"
        }
    },
    {
        name: "Project", path: "/project",
        component: getPageComponent(() =>
            import("@/views/Project")
        ),
        meta: {
            title: "项目"
        }
    },
    {
        name: "NotFound",
        component: NotFound,
        path: "*"
    }
];

export default routerConfig;
